package org.ax.controller.plan;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ax.data.Result;
import org.ax.pojo.plan.Product;
import org.ax.pojo.plan.Work;
import org.ax.service.plan.ProductService;
import org.ax.service.plan.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-16:42
 */
@RestController
@RequestMapping("/work")
public class WorkController {
    @RequestMapping("/find")
    public ModelAndView find(){
        return new ModelAndView("plan/work");
    }
    @Autowired
    WorkService workService;
    @Autowired
    Result result;
    @GetMapping("/list")
    public Result search(String productId, String processId, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int limit){
        Page<Work> workPage = workService.searchWorkPage(new Page(page, limit), productId, processId);
        result.setData(workPage.getRecords());
        result.setCount(workPage.getTotal());
        return result;
    }
    @PostMapping("/add")
    public Result addWork(Work work){
        result.setMsg(workService.addWork(work)?"添加成功":"添加失败");
        return result;

    }
    @PostMapping("/update")
    public Result updateWork(Work work){
        result.setMsg(workService.updWork(work)?"修改成功":"修改失败");
        return result;

    }
    @GetMapping("/patchDel")
    public Result patchDel(String[] ids){
        result.setMsg(workService.deletesWork(ids)?"批量删除成功":"批量删除失败");
        return result;
    }
    @GetMapping("/workList")
    public Result workList(){
        result.setData(workService.selectWorks());
        return result;
    }
}
